part of _;

extension on SettingPage {
  void controller_loadCache() {
    String formatSize(double value) {
      int index = 0;
      while (value > 1024) {
        index++;
        value = value / 1024;
      }
      return "${value.toStringAsFixed(2)} ${['B', 'K', 'M', 'G'][index]}";
    }

    DesktopMultiWindow.invokeMethod(0, "getCacheSize").then((value) {
      cache = value <= 0 ? "暂无缓存" : formatSize(value.toDouble());
      setState(() {});
    });
  }

  Future<void> controller_clearCache() async {
    yShowProgress();
    await DesktopMultiWindow.invokeMethod(0, "clearCache");
    yDismissProgress();
    yToast("清理完成");
    controller_loadCache();
  }
}
